package com.baitiaojun.tenant.config;

import com.baitiaojun.common.constants.WebInterceptorOrderEnum;
import com.baitiaojun.tenant.interceptor.DataSourceInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;


@Configuration
public class DataSourceConfig implements WebMvcConfigurer {

    @Autowired
    private DataSourceInterceptor dataSourceInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(dataSourceInterceptor)
                .addPathPatterns("/**")
                .excludePathPatterns(
                        "/**/captchaImage", "/**/tenant/register", "/**/publicKey",
                        "/webjars/**", "/swagger-ui.html", "/swagger-resources/**",
                        "/*/api-docs", "/doc.html", "/druid/**", "/**/logout"
                )
                .order(WebInterceptorOrderEnum.DYNAMIC_DATASOURCE_INTERCEPTOR);
    }
}
